#include <accent/algorithms/any_of.hpp>
#include "test_base.hpp"

TEST(AnyOf, emptyRange_isFalse)
{
  ivec v = {};
  auto r = all(v);
  ASSERT_FALSE(any_of(r, positive()));
}

TEST(AnyOf, singleFalse_isFalse)
{
  ivec v = { -1 };
  auto r = all(v);
  ASSERT_FALSE(any_of(r, positive()));
}

TEST(AnyOf, singleTrue_isTrue)
{
  ivec v = { 1 };
  auto r = all(v);
  ASSERT_TRUE(any_of(r, positive()));
}

TEST(AnyOf, trueFalse_isTrue)
{
  ivec v = { 1, -1 };
  auto r = all(v);
  ASSERT_TRUE(any_of(r, positive()));
}

TEST(AnyOf, falseTrue_isTrue)
{
  ivec v = { -1, 1 };
  auto r = all(v);
  ASSERT_TRUE(any_of(r, positive()));
}

TEST(AnyOf, trueTrue_isTrue)
{
  ivec v = { 1, 1 };
  auto r = all(v);
  ASSERT_TRUE(any_of(r, positive()));
}

TEST(AnyOf, falseFalse_isFalse)
{
  ivec v = { -1, -1 };
  auto r = all(v);
  ASSERT_FALSE(any_of(r, positive()));
}

struct tracking_positive {
  int& tracker;
  tracking_positive(int& tracker) : tracker(tracker) {}
  bool operator ()(int i) const { ++tracker; return i > 0; }
};

TEST(AnyOf, trueFalse_abortsEarly) {
  int calls = 0;
  ivec v = { 1, -1 };
  auto r = all(v);
  any_of(r, tracking_positive(calls));
  ASSERT_EQ(1, calls);
}
